package com.zelma.mywebsocket.controller;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
//模拟登录操作
@Slf4j
public class CertificationController {
    @Autowired
    StringRedisTemplate redisTemplate;
    @RequestMapping("/getUsername")
    public String getUsername(HttpSession httpSession){
        String name = redisTemplate.opsForValue().get("name");
        httpSession.setAttribute("user",name);
        String username = (String) httpSession.getAttribute("user");
        String s = redisTemplate.opsForValue().get("status");
        httpSession.setAttribute("status",s);
        List<String> agents = redisTemplate.opsForList().range("agents", 0, -1);
        httpSession.setAttribute("agents",agents);
        List<String> users = redisTemplate.opsForList().range("users", 0, -1);
        httpSession.setAttribute("users",users);

        return username;
    }
    @RequestMapping("/getStuats")
    public String getStuats(){
        String s = redisTemplate.opsForValue().get("status");
        return s;
    }
}
